package com.yzr;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description
 * @author: yx-0173
 * @date: 2021-08-24 10:24
 **/
public class MyServlet2 extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取上下文对象
        ServletContext servletContext = getServletContext();
        servletContext.setAttribute("username", "root");
        servletContext.setAttribute("password", "root");
        System.out.println("username = " + servletContext.getAttribute("username"));
        System.out.println("password = " + servletContext.getAttribute("password"));
    }
}
